package Hot100;

import Tree.TreeNode;

public class 将有序数组转换为二叉搜索树 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return findNode(nums, 0, nums.length - 1);
    }

    private TreeNode findNode(int[] nums, int begin, int end) {
        if (begin > end) return null;
        int index = begin + ((end - begin) / 2);
        TreeNode root = new TreeNode(nums[index]);
        root.left = findNode(nums, begin, index - 1);
        root.right = findNode(nums, index + 1, end);
        return root;
    }
}
